package org.test.stream.test.shidianbai;/*

author：ngr
date：{2023/9/8}
*/

import java.util.List;
import java.util.Scanner;

public class ShiDianBanGame {
    static List<Card> pokers=new Poker().getPokers();
    static Integer count=0;//代表牌的索引
    static Integer precount=0;//电脑开始之前的索引

    static Double point=0.0;
    static Double computerPoint=0.0;

    static Scanner scanner=new Scanner(System.in);

    public static void main(String[] args) throws InterruptedException {
        Poker poker = new Poker();
        List<Card> pokers = poker.getPokers();
        System.out.println(pokers);

        System.out.println("开始进行游戏");
        play();




    }
    public static void play() throws InterruptedException {

        System.out.println("玩家请选择操作");
        System.out.println("1,请摸牌");
        System.out.println("2，退出");
        int next = scanner.nextInt();

        switch (next){
            case 1->drawCard();
            case 2->exit();
            default -> {
                System.out.println("你输入的操作码有误");
                play();
            }
        }
    }
    private static void exit() throws InterruptedException {
        System.out.println("电脑开始摸牌");
        computor();
        System.out.println("游戏结束");
        return;
    }

    private static void computor() throws InterruptedException {

        Thread.sleep(2000);
        System.out.println("电脑接到的牌"+pokers.get(count).getColorAndPoint());
        computerPoint+=pokers.get(count++).order;
        if(computerPoint>10.5){
            System.out.println("电脑输了"+computerPoint);
            return;
        }

        if (count-precount==5){
            System.out.println("电脑赢了"+computerPoint);
            return;
        }
        if (computerPoint==10.5&&point==10.5){
            System.out.println("电脑和玩家平局");
            return;
        }
        if (computerPoint>point){
            System.out.println("电脑赢了"+computerPoint);
            return;
        }

        computor();
    }

    //玩家摸牌操作
    private static void drawCard() throws InterruptedException {



        //将接到牌的点数添加进去
        System.out.println("接到的牌是"+pokers.get(count).getColorAndPoint());
        point=point+pokers.get(count++).order;
        precount=count;//就是给电脑索引开始赋值
        if (point>10.5){
            System.out.println("玩家输了"+point);
            return;
        }
        if (count==5){
            System.out.println("玩家直接赢了"+point);
            return;
        }
        play();

    }

}
